<?php
$response = array();
if (isset($_GET['callback'])) {

	$email = $_GET['email'];
	$password = $_GET['password'];
	
	// include db connect class
    require_once __DIR__ . '/db_connect.php';
 
    // connecting to db
    $db = new DB_CONNECT();
	
	$result = mysql_query("SELECT * FROM user_info WHERE email='$email' AND password='$password'");
	$row = mysql_fetch_array($result);
	
	$response["firstname"] = $row[1];
	$response["lastname"] = $row[2];
	$response["age"] = $row[3];
	$response["email"] = $row[4];
	
	$user_id = $row[0];
	$result = mysql_query("SELECT * FROM result_history WHERE user_id=$user_id ORDER BY id DESC LIMIT 1");
	$num_row = mysql_num_rows($result);
	
	if ($num_row == 1) { //this user has played game before
		$row = mysql_fetch_array($result);
		$response["time"] = $row[2];
		$response["total_answer"] = $row[3];
		$response["total_correct"] = $row[4];
		$response["success"] = 5;
		$response["message"] = "get data successfully, include lastest play";
	} else { //this user hasn't ever played game before
		$response["success"] = 6;
		$response["message"] = "get data successfully, not include lastest play";
	}

	//$arr = array("element1","element2",array("element31","element32"));
	
	echo $_GET['callback']."(".json_encode($response).");";
	
}

?>